<?php
EvTicker::add('#ticker', array('height'=>560, 'pause'=>5000));

$this->pageTitle = Yii::app()->name . " - Pemantauan ($total Berita)";
?>

<h1>Berita dari senkom.or.id &amp; SMS Center (081387244622)</h1>

<div class="ticker">
	<div id="ticker">
		<ul id="news">
			<?php
			foreach ($models as $model) {
				$this->renderPartial('_viewMonitor', array('data'=>$model));
			}
			?>
		</ul>
	</div>
</div>

<?php
ELoading::register();
$url = Yii::app()->urlManager->createUrl('news/monitor');
?>

<script type="text/javascript">
	var _lastUpdate = <?php echo $lastUpdate ?>;

	function check() {
		$.loading(false);
		$.loading(true, {onAjax:true, text: 'Membaharui berita...'});
		data = {
			"lastUpdate": _lastUpdate,
			"ajax": 'news-monitor'
		};
		$.getJSON("<?php echo $url ?>", data, refresh);
	}

	function refresh(json) {
		$.loading(false);
		if (json.lastUpdate != _lastUpdate) {
			$('#news').stop(false, true).html(json.newses.join(''));
			$.loading(true, {text: 'Berita terbaharui.', max: 3000});
			_lastUpdate = json.lastUpdate;
			document.title = document.title.replace(/\d+/, json.total);
		}
	}
</script>

<?php
$script = "setInterval(check, 60000);";
Yii::app()->clientScript->registerScript('init', $script);
?>
